// export interface IndexModelState {
//     bannerList: Array<any>;
// }

export interface IndexModelType {
    namespace: 'banner';
    state: Array<any>;
    reducers: {
        save: any,
        delItem: any,
        setItemAction: any,
        getDetail: any
    };
}

const IndexModel: IndexModelType = {
    namespace: 'banner',
    state: [],
    reducers: {
        save(state: any) {
            const newState = Array.from(state)
            newState.push({
                img: "",
                url: ""
            })
            return newState
        },
        getDetail(state: any, action: any) {
            let newState = JSON.parse(JSON.stringify(Array.from(state)))
            if (action.res == []) {
                newState = []
            } else {
                newState = action.res
            }
            return newState
        },
        delItem(state: any, action: any) {
            const newState = Array.from(state)
            newState.splice(action.index, 1)
            return newState
        },
        setItemAction(state: any, action: any) {
            const newState = JSON.parse(JSON.stringify(Array.from(state)))
            console.log(newState, action)
            newState[action.index][action.action] = action.val
            return newState
        }
    },
};

export default IndexModel;